from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.support.wait import WebDriverWait
from pages.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy as By


class MinePage(BasePage):
    #定位器
    enter_mine_info_locator = (
    By.XPATH, '//android.widget.TextView[@resource-id="com.xiachufang:id/tv_name" and @text="关注"]')
    fans_locator = (By.XPATH, '//android.widget.TextView[@resource-id="com.xiachufang:id/tv_name" and @text="粉丝"]')
    fans_info_locator = (
    By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/navigation_bar_title_layout")')
    interest_locator = (
    By.XPATH, '//android.widget.TextView[@resource-id="com.xiachufang:id/tv_name" and @text="关注"]')
    interest_info_locator = (By.ID, 'com.xiachufang:id/navigation_bar_title_layout')
    personal_info_locator = (By.ID, 'com.xiachufang:id/main_profile_desc_tv')
    get_personal_info_locator = (By.XPATH, '//android.widget.TextView[@text="个人信息"]')
    edit_btn_locator = (By.ID, 'com.xiachufang:id/navigation_img_view')
    edit_personal_info_locator = (By.ID, 'com.xiachufang:id/edit_user_config')
    edit_username_locator = (By.ID, 'com.xiachufang:id/profile_setting_name')
    save_btn_locator = (By.ID, 'com.xiachufang:id/navigation_right_btn')
    save_edit_info_locator = (By.XPATH, '//android.widget.EditText[@resource-id="com.xiachufang:id/profile_setting_name"]')
    vip_btn_locator = (By.ID,'com.xiachufang:id/ll_prime')
    vip_info_locator = (By.XPATH,'//android.widget.TextView[@resource-id="com.xiachufang:id/navigation_bar_title_layout"]')
    #进入我的页面
    def get_enter_mine_info(self):
        return self.driver.find_element(*self.enter_mine_info_locator).text

    #点击粉丝
    def click_fans(self):
        self.driver.find_element(*self.fans_locator).click()

    #获取粉丝页面的信息
    def get_fans_info(self):
        return self.driver.find_element(*self.fans_info_locator).text

    #点击关注
    def click_interest(self):
        self.driver.find_element(*self.interest_locator).click()

    #获取关注页面的信息
    def get_interest_info(self):
        return self.driver.find_element(*self.interest_info_locator).text

    #点击个人简介
    def click_personal_info(self):
        self.driver.find_element(*self.personal_info_locator).click()

    #获取个人简介页面的信息
    def get_personal_info(self):
        return self.driver.find_element(*self.get_personal_info_locator).text

    #点击个人信息界面的编辑按钮
    def click_edit_btn(self):
        self.driver.find_element(*self.edit_btn_locator).click()

    #点击编辑个人资料
    def click_edit_personal_info(self):
        self.driver.find_element(*self.edit_personal_info_locator).click()

    #清空用户名
    def clear_username(self):
        self.driver.find_element(*self.edit_username_locator).clear()
    #输入用户名
    def input_username(self, username):
        self.driver.find_element(*self.edit_username_locator).send_keys(username)

    #点击保存按钮
    def click_save_btn(self):
        self.driver.find_element(*self.save_btn_locator).click()

    #返回弹窗信息
    def get_save_info(self):
        return self.driver.find_element(*self.save_edit_info_locator).text

    #点击开通下厨房会员
    def click_vip_btn(self):
        self.driver.find_element(*self.vip_btn_locator).click()
    #点击开通下厨房会员后的返回信息
    def get_vip_info(self):
        return self.driver.find_element(*self.vip_info_locator).text
